package com.surenpi.jenkins.client.computer;

import com.google.common.net.UrlEscapers;
import com.surenpi.jenkins.client.BaseModel;
import com.surenpi.jenkins.client.JenkinsClient;
import java.io.IOException;
import java.util.List;

public class Computer extends BaseModel {
   private String displayName;
   private JenkinsClient client;
   List<Computer> computer;

   public List<Computer> getComputers() {
      return this.computer;
   }

   public void setComputer(List<Computer> computer) {
      this.computer = computer;
   }

   public void setClient(JenkinsClient client) {
      this.client = client;
   }

   public JenkinsClient getClient() {
      return this.client;
   }

   public Computer() {
   }

   public Computer(String displayName) {
      this();
      this.displayName = displayName;
   }

   public String getDisplayName() {
      return this.displayName;
   }

   public ComputerWithDetails details() throws IOException {
      String name;
      if ("master".equals(this.displayName)) {
         name = "(master)";
      } else {
         name = UrlEscapers.urlPathSegmentEscaper().escape(this.displayName);
      }

      ComputerWithDetails computerWithDetails = (ComputerWithDetails)this.client.get("/computer/" + name + "/?depth=2", ComputerWithDetails.class);
      computerWithDetails.setClient(this.client);
      return computerWithDetails;
   }

   public boolean equals(Object obj) {
      if (this == obj) {
         return true;
      } else if (obj == null) {
         return false;
      } else if (this.getClass() != obj.getClass()) {
         return false;
      } else {
         Computer other = (Computer)obj;
         if (this.computer == null) {
            if (other.computer != null) {
               return false;
            }
         } else if (!this.computer.equals(other.computer)) {
            return false;
         }

         if (this.displayName == null) {
            if (other.displayName != null) {
               return false;
            }
         } else if (!this.displayName.equals(other.displayName)) {
            return false;
         }

         return true;
      }
   }

   public int hashCode() {
      int prime = 31;
      int result = 1;
      result = 31 * result + (this.computer == null ? 0 : this.computer.hashCode());
      result = 31 * result + (this.displayName == null ? 0 : this.displayName.hashCode());
      return result;
   }
}
